/**
 * Copyright 2012 Alfredo "Rainbowbreeze" Morresi
 * 
 * This file is part of Eureka! project.
 * 
 * Eureka! is free software: you can redistribute it and/or modify it under the
 * terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
 * Eureka! is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with Eureka!. If not, see http://www.gnu.org/licenses/.
 */
package it.rainbowbreeze.eureka.logic;

import it.rainbowbreeze.eureka.data.AppPreferencesDao;
import it.rainbowbreeze.eureka.domain.FilterCategories;
import it.rainbowbreeze.libs.common.IRainbowLogFacility;
import it.rainbowbreeze.libs.common.RainbowResultOperation;
import it.rainbowbreeze.libs.logic.RainbowLogicManager;
import android.content.Context;

/**
 * @author Alfredo "Rainbowbreeze" Morresi
 *
 */
public class LogicManager extends RainbowLogicManager {
    // ------------------------------------------ Private Fields
    private static final String LOG_HASH = LogicManager.class.getSimpleName();
    private final AppPreferencesDao mAppPreferencesDao;

    // -------------------------------------------- Constructors
    public LogicManager(IRainbowLogFacility logFacility,
            AppPreferencesDao appPreferencesDao, String currentAppVersion) {
        super(logFacility, appPreferencesDao, currentAppVersion);
        mAppPreferencesDao = appPreferencesDao;
    }


    // --------------------------------------- Public Properties

    // ------------------------------------------ Public Methods
    
    // ----------------------------------------- Private Methods
    /* (non-Javadoc)
     * @see it.rainbowbreeze.libs.logic.RainbowLogicManager#executeUpgradeTasks(android.content.Context, java.lang.String)
     */
    @Override
    protected RainbowResultOperation<Void> executeUpgradeTasks(Context context,
            String startingAppVersion) {
        
        int[] categorieIds = mAppPreferencesDao.getCategoryIds(); 
        if (null == categorieIds || 0 == categorieIds.length) {
            //select all filters
            mAppPreferencesDao.setMeasureIds(new int[] {1, 2, 3, 4, 5, 6, 7});
            //initial state: all categories selected
            mAppPreferencesDao.setCategoryIds(FilterCategories.getAllIds());
            mAppPreferencesDao.save();
        }
        return RainbowResultOperation.OK;
    }
    
    // ----------------------------------------- Private Classes
}
